package com.framework.view.indicator.indicators.configs;

import android.graphics.Color;

import com.framework.view.indicator.model.IndicatorShapeType;
import com.framework.view.indicator.model.StrokeType;

/**
 * 点指示器配置
 *
 * @author liangzx
 * @version 1.0
 * @time 2019-12-13 17:37
 **/
public class PointIndicatorConfig extends AbstractIndicatorConfig<PointIndicatorConfig> {

    /**
     * 未选中宽度
     */
    int normalHeight;
    /**
     * 未选中高度
     */
    private int normalWidth;
    /**
     * 选中宽度
     */
    private int selectedWidth;
    /**
     * 选中高度
     */
    private int selectedHeight;
    /**
     * 圆角矩形圆角大小
     */
    private int roundRadius;
    /**
     * 左间距
     */
    private int pendingLeft;
    /**
     * 右间距
     */
    private int pendingRight;
    /**
     * 未选中颜色
     */
    private int normalColor;
    /**
     * 选中颜色
     */
    private int selectedColor;
    /**
     * 空心类型
     */
    private @StrokeType
    int strokeStyle;
    /**
     * 边框宽度
     */
    private float strokeWidth;

    private PointIndicatorConfig() {
    }

    /**
     * 工厂方法，默认矩形及整个Item宽度、白色
     *
     * @return
     */
    public static PointIndicatorConfig factory() {
        PointIndicatorConfig config = new PointIndicatorConfig();
        config.setCircleType(10, 20)
                .setNormalColor(Color.WHITE)
                .setSelectedColor(Color.BLACK);
        return config;
    }

    /**
     * 设置形状为矩形及两种状态的高宽度
     *
     * @param normalWidth    未选中的宽度
     * @param normalHeight   未选中的高度
     * @param selectedWidth  选中的宽度
     * @param selectedHeight 选中的高度
     * @return
     */
    public PointIndicatorConfig setRectType(int normalWidth, int normalHeight, int selectedWidth, int selectedHeight) {
        setShapeType(IndicatorShapeType.RECT);
        this.normalWidth = normalWidth;
        this.normalHeight = normalHeight;
        this.selectedWidth = selectedWidth;
        this.selectedHeight = selectedHeight;
        return this;
    }

    /**
     * 设置形状为矩形及两种状态的高宽度，高宽度相同
     *
     * @param normalWH   未选中的高宽度
     * @param selectedWH 选中的高宽度
     * @return
     */
    public PointIndicatorConfig setRectType(int normalWH, int selectedWH) {
        return setRectType(normalWH, normalWH, selectedWH, selectedWH);
    }

    /**
     * 设置形状为圆角矩形及两种状态的高宽度
     *
     * @param normalWidth    未选中的宽度
     * @param normalHeight   未选中的高度
     * @param selectedWidth  选中的宽度
     * @param selectedHeight 选中的高度
     * @return
     */
    public PointIndicatorConfig setRoundRectType(int normalWidth, int normalHeight, int selectedWidth, int selectedHeight) {
        setShapeType(IndicatorShapeType.ROUND_RECT);
        this.normalWidth = normalWidth;
        this.normalHeight = normalHeight;
        this.selectedWidth = selectedWidth;
        this.selectedHeight = selectedHeight;
        return this;
    }

    /**
     * 设置形状为圆角矩形及两种状态的高宽度，高宽度相同
     *
     * @param normalWH   未选中的高宽度
     * @param selectedWH 选中的高宽度
     * @return
     */
    public PointIndicatorConfig setRoundRectType(int normalWH, int selectedWH) {
        return setRoundRectType(normalWH, normalWH, selectedWH, selectedWH);
    }

    /**
     * 设置形状为圆形及两种状态的半径
     *
     * @param normalRadius   未选中的半径
     * @param selectedRadius 选中的半径
     * @return
     */
    public PointIndicatorConfig setCircleType(int normalRadius, int selectedRadius) {
        setShapeType(IndicatorShapeType.CIRCLE);
        this.normalWidth = normalRadius;
        this.normalHeight = normalRadius;
        this.selectedWidth = selectedRadius;
        this.selectedHeight = selectedRadius;
        return this;
    }

    /**
     * 设置形状为圆形及半径
     *
     * @param radius 半径
     * @return
     */
    public PointIndicatorConfig setCircleType(int radius) {
        return setCircleType(radius, radius);
    }

    /**
     * 圆角矩形圆角大小
     *
     * @param roundRadius
     * @return
     */
    public PointIndicatorConfig setRoundRadius(int roundRadius) {
        this.roundRadius = roundRadius;
        return this;
    }

    /**
     * 设置边框及边框宽度
     *
     * @param strokeStyle
     * @param strokeWidth
     * @return
     */
    public PointIndicatorConfig setStroke(@StrokeType int strokeStyle, float strokeWidth) {
        this.strokeStyle = strokeStyle;
        this.strokeWidth = strokeWidth;
        return this;
    }

    /**
     * 设置左右间距
     *
     * @param panding
     * @return
     */
    public PointIndicatorConfig setPanding(int panding) {
        this.pendingLeft = panding;
        this.pendingRight = panding;
        return this;
    }

    /**
     * 左间距
     *
     * @param pendingLeft
     * @return
     */
    public PointIndicatorConfig setPendingLeft(int pendingLeft) {
        this.pendingLeft = pendingLeft;
        return this;
    }

    /**
     * 右间距
     *
     * @param pendingRight
     * @return
     */
    public PointIndicatorConfig setPendingRight(int pendingRight) {
        this.pendingRight = pendingRight;
        return this;
    }

    /**
     * 未选中颜色
     *
     * @param normalColor
     * @return
     */
    public PointIndicatorConfig setNormalColor(int normalColor) {
        this.normalColor = normalColor;
        return this;
    }

    /**
     * 选中颜色
     *
     * @param selectedColor
     * @return
     */
    public PointIndicatorConfig setSelectedColor(int selectedColor) {
        this.selectedColor = selectedColor;
        return this;
    }

    @Override
    boolean isSupportShape(int shapeType) {
        return shapeType == IndicatorShapeType.RECT
                || shapeType == IndicatorShapeType.ROUND_RECT
                || shapeType == IndicatorShapeType.CIRCLE;
    }

    public int getNormalWidth() {
        if (0 == normalWidth) {
            return selectedWidth;
        }
        return normalWidth;
    }

    public int getSelectedWidth() {
        if (0 == selectedWidth) {
            return normalWidth;
        }
        return selectedWidth;
    }

    public int getSelectedHeight() {
        if (0 == selectedHeight) {
            return normalHeight;
        }
        return selectedHeight;
    }

    public int getNormalHeight() {
        if (0 == normalHeight) {
            return selectedHeight;
        }
        return normalHeight;
    }

    public int getRoundRadius() {
        return roundRadius;
    }

    public int getPendingLeft() {
        return pendingLeft;
    }

    public int getPendingRight() {
        return pendingRight;
    }

    public int getNormalColor() {
        if (0 == normalColor) {
            return selectedColor;
        }
        return normalColor;
    }

    public int getSelectedColor() {
        if (0 == selectedColor) {
            return normalColor;
        }
        return selectedColor;
    }

    public int getStrokeStyle() {
        return strokeStyle;
    }

    public float getStrokeWidth() {
        return strokeWidth;
    }
}
